package com.huihua.it.controller;

import com.huihua.it.common.ResultData;
import com.huihua.it.enums.CodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class LanguageController {

    @Autowired
    private MyMessageSource myMessageSource;

    @GetMapping("test")
    public ResultData test() {
        return ResultData.success(CodeEnum.SUCCESS);
    }



    @GetMapping(value="/language")
    public Object multilingualSwitching(@RequestParam("lang") String lang){
        if(StringUtils.isEmpty(lang)){
            lang = I18nEnum.EN_US.code;
        }
        Map sourceFromCacheMap = myMessageSource.getSourceFromCacheMap(lang, null);

//        Locale[] locales = Locale.getAvailableLocales();
//        for (Locale locale : locales) {
//            log.info("支持的语言：{} {}_{}",locale.getDisplayName(), locale.getLanguage(), locale.getCountry());
//        }

        return sourceFromCacheMap;
    }

    @GetMapping(value="/language/list")
    public Object getLanguageList(@RequestParam("lang") String lang){
        return null;
    }
}
